# coding: utf8
import uuid
import time
user_id = auth.user.id if auth.user else 0

default_change_note = "new record created"

'''
to add auditing to any table simply apend the audit_table variable to the end of the table.

usage examples:

by individual field for testing

db.define_table('address',
    Field('street'),
    Field('city'),
    Field('province'),
    Field('postal_code'),    
    unique_id,
    active,
    created_on,
    created_by,
    modified_on,
    note,
    )
  
Alternativly 
    
db.define_table('address',
    Field('street'),
    Field('city'),
    Field('province'),
    Field('postal_code'),
    audit_table,
    )

'''
#audit field group

unique_id      = Field('unique_id', default=uuid.uuid4(), writable=False, readable=False)
active         = Field('active', 'boolean', default=True, comment='set Active off to delete record')
created_by     = Field('created_by', db.auth_user, default=user_id, writable=False)
created_on     = Field('created_on', 'datetime', default=request.now, writable=False)
modified_by    = Field('modified_by', db.auth_user, default=user_id, update=user_id, writable=False)
modified_on    = Field('modified_on', 'datetime', default=request.now, update=request.now, writable=False)
note   = Field('change_notes', 'text',default=default_change_note)

# if audit is on we use a full audit table

if session._uc_audit_on == "True":
    audit_table=db.Table(None,'audit',
       unique_id,
        active,
        created_by,
#        created_on,
        modified_by,
        modified_on,
        note,
        )
else:
    audit_table=db.Table(None,'audit',
       unique_id,
       )
